<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.huan.service.NewsService" %>
<%@ page import="com.huan.service.NewsServiceImpl" %>
<%@ page import="com.huan.entity.News" %>

<html>
    <head>
        <link href="<%=request.getContextPath() %>/css/common.css" rel="stylesheet" type="text/css"/>
        <script type="application/javascript" src="<%=request.getContextPath()%>/ckeditor/ckeditor.js"></script>
    </head>
    <body>
        <form name="dataFrm" id="dataFrm" action="doAddNews.jsp"
              enctype="multipart/form-data" method="post">
            <%
            request.setCharacterEncoding("UTF-8");
                    response.setCharacterEncoding("UTF-8");
                News news = new News();
                String idStr = request.getParameter("id");
                int id = 0;
                if (idStr != null && !"".equals(idStr)) {
                    id = Integer.parseInt(idStr);
                    NewsService newsService = new NewsServiceImpl();
                    news = newsService.getNewsListById(id);
                }
            %>
            <input type="hidden" name="updateId" value="<%=id%>"/>
            <table width="100%" border="0" cellspacing="5" cellpadding="0">
                <thead>
                <tr>
                    <td align="center" colspan="2" class="text_tabledetail2">
                        <%=id > 0 ? "修改新闻" : "增加新闻"%>
                    </td>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td style="text-align:right;" class="text_tabledetail2">分类</td>
                    <td style="text-align:left;">
                        <!-- 列出所有的新闻分类 -->
                        <select name="categoryId">
<%--                            <%if (news.getCategoryId() == null) {%>--%>
<%--                            <option value="1">国内</option>--%>
<%--                            <option value="2">国际</option>--%>
<%--                            <option value="3">娱乐</option>--%>
<%--                            <option value="4">军事</option>--%>
<%--                            <option value="5">财经</option>--%>
<%--                            <option value="6">天气</option>--%>
<%--                            <%} else if (news.getCategoryId() > 0) {%>--%>
                            <option value="1" <%=news.getCategoryId() == 1 ? "selected" : ""%>>国内</option>
                            <option value="2" <%=news.getCategoryId() == 2 ? "selected" : ""%>>国际</option>
                            <option value="3" <%=news.getCategoryId() == 3 ? "selected" : ""%>>娱乐</option>
                            <option value="4" <%=news.getCategoryId() == 4 ? "selected" : ""%>>军事</option>
                            <option value="5" <%=news.getCategoryId() == 5 ? "selected" : ""%>>财经</option>
                            <option value="6" <%=news.getCategoryId() == 6 ? "selected" : ""%>>天气</option>
<%--                            <%}%>--%>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right;" class="text_tabledetail2">标题</td>
                    <td style="text-align:left;"><input type="text" name="title" value="<%=news.getTitle()%>"/></td>
                </tr>
                <tr>
                    <td style="text-align:right;" class="text_tabledetail2">作者</td>
                    <td style="text-align:left;"><input type="text" name="author" value="<%=news.getAuthor()%>"/></td>
                </tr>

                <tr>
                    <td style="text-align:right;" class="text_tabledetail2">摘要</td>
                    <td style="text-align:left;"><textarea id="summary" name="summary" rows="8"
                                                           cols="50"><%=news.getSummary()%></textarea>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right;" class="text_tabledetail2">内容</td>
                    <td style="text-align:left;">
                        <div id="xToolbar"></div>
                        <textarea id="newscontent" name="newscontent" rows="8"
                                  cols="30">"<%=news.getContent()%></textarea></td>
                </tr>

                <tr>
                    <%if (id > 0) {%>
                    <td style="text-align:right;" class="text_tabledetail2">图片路径</td>
                    <td style="text-align:left;"><input type="file" name="picPath" value="<%=news.getPicpath()%>"/></td>

                    <% } else { %>
                    <td style="text-align:right;" class="text_tabledetail2">上传图片</td>
                    <td style="text-align:left;"><input type="file" name="picPath" value=""/></td>
                    <% } %>
                </tr>
                <tr>
                    <td style="text-align:center;" colspan="2">
                        <button type="submit" class="page-btn" name="save"><%=id > 0 ? "修改" : "保存"%>
                        </button>
                        <button type="button" class="page-btn" name="return"
                                onclick="javascript:location.href='newsDetailList.jsp'">返回
                        </button>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>

        <script type="application/javascript">
            function doUpdateNews() {
                window.location.href = "doUpdateNews.jsp";
            }

            CKEDITOR.replace("newscontent")
        </script>
    </body>
</html>